package com.xin.data.simbapesa.utils;

import android.content.Context;
import android.text.TextUtils;

import com.xin.data.simbapesa.SimbaApp;
import com.xin.data.simbapesa.base.BaseParams;
import com.xin.data.simbapesa.obj.SimbaUserProcess;


public class OrderUtils {


    public static int getOrderStatus() {
        int state = 0;
        String applyStatus;
        String orderStatus;
        SimbaUserProcess userProcessBean = SimbaApp.getInstance().getProcess();
        if (userProcessBean != null) {
            applyStatus = userProcessBean.getApplyStatus();
            orderStatus = userProcessBean.getOrderStatus();
            if (!TextUtils.isEmpty(applyStatus) && (applyStatus.equals("CREATED") || applyStatus.equals("SYS_CHECK") || applyStatus.equals("SYS_APROVAL") || applyStatus.equals("MANU_APROVAL") || applyStatus.equals("DS_APROVAL"))) {
                //in review
                state = 1;
            } else if ((!TextUtils.isEmpty(applyStatus) && (applyStatus.equals("SYS_DENIED") || applyStatus.equals("MANU_DENIED") || applyStatus.equals("DS_DENIED"))) || (!TextUtils.isEmpty(orderStatus) && orderStatus.equals("DENIED"))) {
                //Rejected
                state = 2;
            } else if (!TextUtils.isEmpty(orderStatus) && (orderStatus.equals("CREATED") || orderStatus.equals("LENDING"))) {
                //disbursement in progress
                state = 3;
            } else if (!TextUtils.isEmpty(orderStatus) && (orderStatus.equals("LOANED") || orderStatus.equals("OVERDUE") || orderStatus.equals("BAD_DEBT"))) {
                //Repayment in progress
                state = 4;
            } else if (!TextUtils.isEmpty(orderStatus) && (orderStatus.equals("OVERDUE") || orderStatus.equals("BAD_DEBT"))) {
                //Repayment overdue
                state = 5;
            } else if (!TextUtils.isEmpty(orderStatus) && (orderStatus.equals("SETTLE") || orderStatus.equals("OVERDUE_SETTLE") || orderStatus.equals("ANNUAL_SETTLE") || orderStatus.equals("OVERDUE_ANNUAL_SETTLE"))) {
                //Repayment successful
            }
        }
        return state;
    }

    public static boolean isAdSource(Context context){
        String isAdSource=SpUtils.get_string(context,SpUtils.KEY_ISADSOURCE,"");
        if(isAdSource.equals("YES")){
            return true;
        }
        return false;
    }

    public static boolean isForceUpdate(Context context) {

        if ( SimbaApp.getInstance().getAppInfo() != null &&  SimbaApp.getInstance().getAppInfo().getUpdateInfo() != null &&  SimbaApp.getInstance().getAppInfo().getUpdateInfo().getForceUpdate().equals("YES")) {

            int code1 = BaseParams.getVersion(context);
            int code2 = SimbaApp.getInstance().getAppInfo().getUpdateInfo().getUpdateCode();
            for (int code :  SimbaApp.getInstance().getAppInfo().getUpdateInfo().getIgnoreUpdate()) {
                if (code1 == code) {
                    return false;
                }
            }

            return code2 > code1;

        }
        return false;
    }

    public static boolean isUpdate(Context context) {
        if ( SimbaApp.getInstance().getAppInfo() != null &&  SimbaApp.getInstance().getAppInfo().getUpdateInfo() != null &&  SimbaApp.getInstance().getAppInfo().getUpdateInfo().getForceUpdate().equals("NO")) {

            int code1 = BaseParams.getVersion(context);
            int code2 =  SimbaApp.getInstance().getAppInfo().getUpdateInfo().getUpdateCode();
            for (int code :  SimbaApp.getInstance().getAppInfo().getUpdateInfo().getIgnoreUpdate()) {
                if (code1 == code) {
                    return false;
                }
            }

            return code2 > code1;

        }
        return false;
    }


}
